﻿// -----------------------------------------------------------------------
// <copyright file="GameOverScreen.cs" company="Diddly Squad">

// </copyright>
// -----------------------------------------------------------------------
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using System;

namespace DiddlySquat
{

	/// <summary>
	/// Screen that gets displayed when Player dies
	/// </summary>
	public class GameOverScreen : Screen
	{
		//Background texture for the screen
		readonly Texture2D gameOverScreenBackground;

		public int Points;

		private readonly SpriteFont font;
		private readonly SpriteFont menuFont;
		
		private readonly GraphicsDeviceManager graphicsDeviceManager;

		/// <summary>
		/// Initializes a new instance of the <see cref="GameOverScreen"/> class.
		/// </summary>
		/// <param name="theContent">The content.</param>
		/// <param name="theScreenEvent">The screen event.</param>
		/// <param name="graphics">The graphics.</param>
		public GameOverScreen(ContentManager theContent, EventHandler theScreenEvent, GraphicsDeviceManager graphics)
			: base(theScreenEvent)
		{
			//Load the background texture for the screen
			gameOverScreenBackground = theContent.Load<Texture2D>("GameScreen");
			font = theContent.Load<SpriteFont>("fonts/gameoverfont");
			menuFont = theContent.Load<SpriteFont>("fonts/menufont");
			this.graphicsDeviceManager = graphics;
		}
		
		/// <summary>
		/// Updates the specified screen.
		/// </summary>
		/// <param name="theTime">The time.</param>
		public override void Update(GameTime theTime)
		{
			state = Keyboard.GetState();

			if (CheckKey(Keys.Enter) || CheckKey(Keys.Space))
			{
				ScreenEvent.Invoke(this, new EventArgs());
			}

			base.Update(theTime);
			oldState = Keyboard.GetState();
		}

		/// <summary>
		/// Draws the specified text to the batch.
		/// </summary>
		/// <param name="theBatch">The batch.</param>
		public override void Draw(SpriteBatch theBatch)
		{
			var drawPositionY = 100;

			theBatch.Draw(gameOverScreenBackground, Vector2.Zero, Color.White);

			string text = "GAME OVER!\n" + "You got " + Points + " points!";

			//theBatch.DrawString(font, text, new Vector2(10f, 60f), Color.White);
			theBatch.DrawString(font, text, new Vector2(graphicsDeviceManager.GraphicsDevice.Viewport.Width / 2 - (int)font.MeasureString(text).X, drawPositionY), Color.White);

			const string menuText = Constants.MenuOptionBack;

			drawPositionY += 5 * font.LineSpacing;

			theBatch.DrawString(menuFont, menuText, new Vector2(graphicsDeviceManager.GraphicsDevice.Viewport.Width / 2 - (int)menuFont.MeasureString(menuText).X, drawPositionY), Constants.SelectedMenuItemColor);

			base.Draw(theBatch);
		}
	}
}
